#!/usr/bin/perl

# convert SimGear GPL license headers to LGPL in specified source file

$file = shift(@ARGV);
$new = "$file.new";

open( IN, "<$file" );
open( OUT, ">$new" );

while ( <IN> ) {
    if ( m/\/\/ This program is free software; you can redistribute it and\/or/ )
    {
	while ( ! m/Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA./ )
	{
	    $_ = <IN>;
	}
	print OUT <<EOF;
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA  02111-1307, USA.
EOF
    } elsif ( m/ \* This program is free software; you can redistribute it and\/or/ )
    {
	while ( ! m/Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA./ )
	{
	    $_ = <IN>;
	}
	print OUT <<EOF;
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
EOF
    } else {
	print OUT $_;
    }
}

close( IN );
close( OUT );

rename( $new, $file );
